package com.hermit.util;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 */
public class ReqResult extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public ReqResult() {
        put("code", 1);
        put("msg", "success");
    }

    public static ReqResult error() {
        return error(110, "出错啦");
    }

    public static ReqResult error(String msg) {
        return error(111, msg);
    }

    public static ReqResult error(int code, String msg) {
        ReqResult r = new ReqResult();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static ReqResult ok(String msg) {
        ReqResult r = new ReqResult();
        r.put("msg", msg);
        return r;
    }

    public static ReqResult ok(Map<String, Object> map) {
        ReqResult r = new ReqResult();
        r.putAll(map);
        return r;
    }

    public static ReqResult ok() {
        return new ReqResult();
    }

    @Override
    public ReqResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
